﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CssdAssistantClient.Controls
{
    /// <summary>
    /// CtrlQuestionItem.xaml 的交互逻辑
    /// </summary>
    public partial class CtrlQuestionItem : UserControl
    {
        public CtrlQuestionItem()
        {
            InitializeComponent();
        }

        #region 附加属性 Index
        public int Index { get { return (int)GetValue(IndexProperty); } set { SetValue(IndexProperty, value); } }
        public static readonly DependencyProperty IndexProperty = DependencyProperty.Register("Index", typeof(int), typeof(CtrlQuestionItem), new PropertyMetadata(default(int)));
        #endregion

        #region 附加属性 Title
        public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } }
        public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(CtrlQuestionItem), new PropertyMetadata(default(string)));
        #endregion

        #region 附加属性 ListOption
        public IEnumerable ListOption { get { return (IEnumerable)GetValue(ListOptionProperty); } set { SetValue(ListOptionProperty, value); } }
        public static readonly DependencyProperty ListOptionProperty = DependencyProperty.Register("ListOption", typeof(IEnumerable), typeof(CtrlQuestionItem), new PropertyMetadata(default(IEnumerable)));
        #endregion


        #region 附加属性 QuestionType
        public int QuestionType { get { return (int)GetValue(QuestionTypeProperty); } set { SetValue(QuestionTypeProperty, value); } }
        public static readonly DependencyProperty QuestionTypeProperty = DependencyProperty.Register("QuestionType", typeof(int), typeof(CtrlQuestionItem), new PropertyMetadata(default(int), OnQuestionChanged));

        private static void OnQuestionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var newValue = (int)e.NewValue;
            var ctrl = d as CtrlQuestionItem;

            ctrl.grid1.Visibility = Visibility.Collapsed;
            ctrl.grid2.Visibility = Visibility.Collapsed;
            ctrl.grid3.Visibility = Visibility.Collapsed;
            ctrl.grid4.Visibility = Visibility.Collapsed;

            if (newValue == 1)
            {
                ctrl.grid1.Visibility = Visibility.Visible;
            }
            else if (newValue == 2)
            {
                ctrl.grid2.Visibility = Visibility.Visible;
            }
            else if (newValue == 3)
            {
                ctrl.grid3.Visibility = Visibility.Visible;
            }
            else if (newValue == 4)
            {
                ctrl.grid4.Visibility = Visibility.Visible;
            }
        }
        #endregion

    }
}
